package com.kx.demo.concurrent;

/**
 * @author kx
 */
public class ThreadUnsafeDemo {

    private static  int data = 0;

    private synchronized static void increment() {
        data++;
    }

    private  synchronized void increment1() {
        data++;
    }

    public static void main(String[] args) throws InterruptedException {

        ThreadUnsafeDemo demo = new ThreadUnsafeDemo();
        ThreadUnsafeDemo demo2 = new ThreadUnsafeDemo();

        Thread thread1 = new Thread() {
            @Override
            public void run() {
                for (int i1 = 0; i1 < 100000; i1++) {

                }
//                System.out.println(data);
            }
        };
        thread1.start();
        Thread thread2 = new Thread() {
            @Override
            public void run() {
                for (int i1 = 0; i1 < 100000; i1++) {
                    synchronized (demo2){
                        data++;
                    }
                }
            }
        };

        thread2.start();
        thread1.join();
        thread2.join();

        System.out.println(data);
    }

}
